|
|
|
|
|
|
|
Examples Filename: ApiFind.frm |
|
|
|
|
|
|
|
|
In the example shown in Figure 28.2, you can search for a state code in a list box full of state codes. Click the Search button to invoke the Click event. Heres the code: |
|
|
|
 |
|
|
|
|
Private Sub cmdSearch_Click()
Dim strSearch As String
Dim lngPos As Long
strSearch = InputBox$("Enter String To Find:", "Search")
With lstStates
If strSearch = "" Then
.ListIndex = 0
Else lngPos = SendMessage(.hwnd, _
LB_FINDSTRING, _
-1, _
ByVal strSearch) If lngPos >= 0 Then
.ListIndex = lngPos
End If
End If
End With
End Sub |
|
|
|
|
|
|
|
|
Figure 28.2
Finding a string in a list box using SendMessage(). |
|
|
|
|
|
|
|
|
The SendMessage() API always expects a handle to a window as the first parameter. A handle is a long integer that uniquely identifies a window within the Windows environment. Almost every control you use with Visual Basic is a window, and these controls have an hWnd (handle to a window) property you can use for this parameter. The next parameter is the specific message you want to send to the control. In this case, its a constant value that youll also retrieve from the API Text Viewer. |
|
|
|
|
|